package org.jeecg.modules.util;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.taobao.api.ApiException;
import org.jeecg.common.api.vo.Result;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 王鹏
 * @version 1.0
 * @description    钉钉发送消息的方法
 * @date 2020/8/15 16:41
 */
public class SendMessageToDingding {
    public static Long testsendmessage(String userid, String message) throws ApiException {
        Result result=new Result();
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
        OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request();
        req.setUseridList(userid);
        req.setAgentId(1470238867L);
        req.setToAllUser(false);
        OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
        msg.setMsgtype("text");
        msg.setText(new OapiMessageCorpconversationAsyncsendV2Request.Text());
        msg.getText().setContent(message);
        req.setMsg(msg);
        OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, AccessTokenUtil.getToken());
        Long taskId = rsp.getTaskId();
        return taskId;
    }
}
